package com.pd.backend.service.impl;

import com.pd.backend.entity.PdTransportLineType;
import com.pd.backend.dao.PdTransportLineTypeDao;
import com.pd.backend.service.PdTransportLineTypeService;
import org.springframework.stereotype.Service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;

import javax.annotation.Resource;

/**
 * 线路类型表(PdTransportLineType)表服务实现类
 *
 * @author GuoXinChao.126@gmail.com
 * @since 2023-02-27 17:14:35
 */
@Service("pdTransportLineTypeService")
public class PdTransportLineTypeServiceImpl implements PdTransportLineTypeService {
    @Resource
    private PdTransportLineTypeDao pdTransportLineTypeDao;

    /**
     * 通过ID查询单条数据
     *
     * @param id 主键
     * @return 实例对象
     */
    @Override
    public PdTransportLineType queryById(String id) {
        return this.pdTransportLineTypeDao.queryById(id);
    }

    /**
     * 分页查询
     *
     * @param pdTransportLineType 筛选条件
     * @param pageRequest         分页对象
     * @return 查询结果
     */
    @Override
    public Page<PdTransportLineType> queryByPage(PdTransportLineType pdTransportLineType, PageRequest pageRequest) {
        long total = this.pdTransportLineTypeDao.count(pdTransportLineType);
        return new PageImpl<>(this.pdTransportLineTypeDao.queryAllByLimit(pdTransportLineType, pageRequest), pageRequest, total);
    }

    /**
     * 新增数据
     *
     * @param pdTransportLineType 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportLineType insert(PdTransportLineType pdTransportLineType) {
        this.pdTransportLineTypeDao.insert(pdTransportLineType);
        return pdTransportLineType;
    }

    /**
     * 修改数据
     *
     * @param pdTransportLineType 实例对象
     * @return 实例对象
     */
    @Override
    public PdTransportLineType update(PdTransportLineType pdTransportLineType) {
        this.pdTransportLineTypeDao.update(pdTransportLineType);
        return this.queryById(pdTransportLineType.getId());
    }

    /**
     * 通过主键删除数据
     *
     * @param id 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(String id) {
        return this.pdTransportLineTypeDao.deleteById(id) > 0;
    }
}
